﻿// See https://aka.ms/new-console-template for more information
using HAArtemis.Entity;
string url = "activemq:failover:(tcp://172.16.98.133:61618,tcp://172.16.98.133:61619,tcp://172.16.98.133:61620)?randomize=false&priorityBackup=true";
MqProducer producer = new MqProducer();
var sample = producer.CreateProducer(type: "topic");
///// <summary>
///// 持久化
///// </summary>
//sample.DeliveryMode = Apache.NMS.MsgDeliveryMode.Persistent;

//添加两个消费者用于处理高并发 正常情况下只添加一个就可以了
MqConsumer<Artemis> consumer = new MqConsumer<Artemis>(type:"topic");

DateTime date = DateTime.Now;
testhamq(0, "1");
testhamq(3000, "2");
testhamq(6000, "3");
testhamq(9000, "4");

Console.WriteLine(date - DateTime.Now);
Console.ReadKey();

async void testhamq(int start = 0, string name = "")
{
    string input = "";
    Console.WriteLine("请输入你要打印的内容。");
    int i = start;
    List<Task> taskList = new List<Task>();
    while (i < start + 3000)
    {
        input = name + "-" + i;

        Task task = producer.SendMessage(sample, input);
        taskList.Add(task);
        //Console.Write($"{name}-发送消息：{i}; ");
        await Task.Delay(2);
        i++;
    }
    await Task.WhenAny(taskList);
}